package com.ruoyi.web.controller.order_address;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order_address.domain.OrderAddress;
import com.ruoyi.order_address.service.IOrderAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单地址快照Controller
 * 
 * @author 张富饶
 * @date 2025-05-20
 */
@RestController
@RequestMapping("/order_address/order_address")
public class OrderAddressController extends BaseController
{
    @Autowired
    private IOrderAddressService orderAddressService;

    /**
     * 查询订单地址快照列表
     */
    @PreAuthorize("@ss.hasPermi('order_address:order_address:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderAddress orderAddress)
    {
        startPage();
        List<OrderAddress> list = orderAddressService.selectOrderAddressList(orderAddress);
        return getDataTable(list);
    }

    /**
     * 导出订单地址快照列表
     */
    @PreAuthorize("@ss.hasPermi('order_address:order_address:export')")
    @Log(title = "订单地址快照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderAddress orderAddress)
    {
        List<OrderAddress> list = orderAddressService.selectOrderAddressList(orderAddress);
        ExcelUtil<OrderAddress> util = new ExcelUtil<OrderAddress>(OrderAddress.class);
        util.exportExcel(response, list, "订单地址快照数据");
    }

    /**
     * 获取订单地址快照详细信息
     */
    @PreAuthorize("@ss.hasPermi('order_address:order_address:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(orderAddressService.selectOrderAddressByOrderId(orderId));
    }

    /**
     * 新增订单地址快照
     */
    @PreAuthorize("@ss.hasPermi('order_address:order_address:add')")
    @Log(title = "订单地址快照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderAddress orderAddress)
    {
        return toAjax(orderAddressService.insertOrderAddress(orderAddress));
    }

    /**
     * 修改订单地址快照
     */
    @PreAuthorize("@ss.hasPermi('order_address:order_address:edit')")
    @Log(title = "订单地址快照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderAddress orderAddress)
    {
        return toAjax(orderAddressService.updateOrderAddress(orderAddress));
    }

    /**
     * 删除订单地址快照
     */
    @PreAuthorize("@ss.hasPermi('order_address:order_address:remove')")
    @Log(title = "订单地址快照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(orderAddressService.deleteOrderAddressByOrderIds(orderIds));
    }
}
